<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.ParseException" %>
<%@ page import="com.wzy.Jdbc封装.pojo.News_comment" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:useBean id="comment" class="com.wzy.level.comment.commentServiceImpl.commentServiceImpl"/>
<html>
<head>
    <title>增改数据处理中间站</title>
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    int id = Integer.parseInt(request.getParameter("id"));
    int newsId = Integer.parseInt(request.getParameter("newsId").trim());
    String content = request.getParameter("content");
    String author = request.getParameter("author");
    String ip = request.getParameter("ip").trim();
    String sdate = request.getParameter("date");

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");

    Date date = null ;
    try {
        date = sdf.parse(sdate);
    }catch (ParseException e){
        e.printStackTrace();
    }

    News_comment news_comment = new News_comment();
    news_comment.setNewsId(newsId);
    news_comment.setContent(content);
    news_comment.setAuthor(author);
    news_comment.setIp(ip);
    news_comment.setDate(date);

    int state = Integer.parseInt(request.getParameter("state"));
    
        if(state ==0){
        news_comment.setId(id);

        int update = comment.update(news_comment);
        if(update>0){
            response.sendRedirect(request.getContextPath()+"/comment.jsp");
        }else {
%>
<%="修改失败"%>
<%
    }
}else if(state ==1){
    int insert = comment.insert(news_comment);
    if(insert>0){
        response.sendRedirect(request.getContextPath()+"/comment.jsp");
    }else {
%>
<%="修改失败"%>
<%
        }
    }

%>




















</body>
</html>
<%--<%--%>
<%--    request.setCharacterEncoding("utf-8");--%>
<%--    int id= Integer.parseInt(request.getParameter("id"));--%>
<%--    int newsId = Integer.parseInt(request.getParameter("newsId").trim());--%>
<%--    String content = request.getParameter("content");--%>
<%--    String author = request.getParameter("author");--%>
<%--    String ip = request.getParameter("ip").trim();--%>
<%--    String createDate = request.getParameter("createDate");--%>

<%--    int state = Integer.parseInt(request.getParameter("state"));--%>
<%--    Date date=null;--%>
<%--    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");--%>
<%--    try {--%>

<%--        date = sdf.parse(createDate);--%>
<%--    }catch (ParseException e){--%>
<%--        e.printStackTrace();--%>
<%--    }--%>

<%--    News_comment news_comment = new News_comment();--%>

<%--    news_comment.setContent(content);--%>
<%--    news_comment.setAuthor(author);--%>
<%--    news_comment.setIp(ip);--%>
<%--    news_comment.setDate(date);--%>
<%--    news_comment.setNewsId(newsId);--%>
<%--    if(state ==0){--%>
<%--        news_comment.setId(id);--%>

<%--        int update = comment.update(news_comment);--%>
<%--        if(update>0){--%>
<%--            response.sendRedirect(request.getContextPath()+"/comment.jsp");--%>
<%--        }else {--%>
<%--%>--%>
<%--<%="修改失败"%>--%>
<%--<%--%>
<%--    }--%>
<%--}else if(state ==1){--%>
<%--    int insert = comment.insert(news_comment);--%>
<%--    if(insert>0){--%>
<%--        response.sendRedirect(request.getContextPath()+"/comment.jsp");--%>
<%--    }else {--%>
<%--%>--%>
<%--<%="修改失败"%>--%>
<%--<%--%>
<%--        }--%>
<%--    }--%>


<%--%>--%>